<?php


class GalleryCategory {
	
	private $categories = array();
	
	public function __construct(){
		
		$q = "SELECT * FROM tb_gallery ORDER BY weight desc";
		$r = mysql_query($q);
		while ($data = mysql_fetch_assoc($r)) {
			$q = "SELECT COUNT(id) as count FROM tb_gallery_photo WHERE parent_id = {$data['id']}";
			$t = mysql_fetch_assoc(mysql_query($q));
			$data['count'] = $t['count'];
			$this->categories[$data['id']] = $data;
		}
	}
	
	public function getCategoryNameById($id){
		return $this->categories[$id];
	}
	
	public function getCategories(){
		return $this->categories;
	}
}

?>